import { getUploadToken } from 'service/actions/commonAction'

export default {
  namespace: 'commonAction',

  state: {
    uploadInfo: '',
    catchObj: {
      deviceUpkeep: [true, false],
      deviceUpkeep_add: [true, false],
      deviceUpkeep_edit: [true, false],
      deviceLedger: [true, false],
      deviceLedger_add: [true, false],
      deviceLedger_edit: [true, false],
      deviceCali: [true, false],
      deviceCali_add: [true, false],
      deviceCali_edit: [true, false],
      deviceCali_detail: [true, false],
      previewPlanModal: [true, false],
      deviceCheck: [true, false],
      deviceCheck_add: [true, false],
      deviceCheck_edit: [true, false],
    }
  },

  effects: {
    // 上传文件前所需要的token
    *getToken({ payload }, { put, call }) {
      const data = yield call(getUploadToken, payload)
      if (data.code === '000000') {
        yield put({
          type: 'uploadInfo',
          payload: { uploadInfo: data.data }
        })
      }
      return data
    }
  },

  reducers: {
    uploadInfo(state, { payload: { uploadInfo } }) {
      return { ...state, uploadInfo }
    },
    uploadCatch(state, { payload: { catchObj } }) {
      return { ...state, catchObj }
    },
  },
}
